#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

PID=`pidof -o %PPID /usr/sbin/openvasd`

case "$1" in
	start)
		stat_busy "Starting OpenVAS Server"
		if [ -z "$PID" ]; then 
      echo "openvasd takes *really* long to startup the first time - be patient"
			/usr/sbin/openvasd -D -q >/dev/null 2>&1
			PID=`pidof -o %PPID /usr/sbin/openvasd`
			if [ -z "$PID" ]; then
				stat_fail
			else
				add_daemon openvasd
				stat_done
			fi
		else
			stat_fail
		fi
	;;
	stop)
		stat_busy "Stopping OpenVAS Server"
		[ ! -z "$PID" ]  && kill $PID &> /dev/null
		if [ $? -gt 0 ]; then
			stat_fail
		else
			rm_daemon openvasd
			stat_done
		fi
	;;
	restart)
		$0 stop
		sleep 3
		$0 start
	;;
	*)
		echo "usage: $0 {start|stop|restart}"  
esac

# vim:set ts=2 sw=2 et:
